define([
	'../libs/zepto',
	'../common/base',
	'../common/common_click',
	'../common/dialog',
	'../common/yingSoftPrg',
	'../common/yingSoftCookie',
	'../common/ajax'
],function(){
	var guid = G_Cookie.getGuid();
	var BookID = G_Prg.getCookie('BOOKID');
	var winH=$(window).height();
	if(_getClientType()=='web_iPhone'){
	}else{
		$('.header').after('<a href="#" class="bendi">本地视频</a>');
		$('.bendi').unbind('click').click(function(){
			window.video.jumpToVideoList('a');
		})
	}
	$('.middle_1').css('height',winH-$('#back').height())
	getChapterMenu(guid,BookID);
	
	function getChapterMenu(guid,BookID) {
	    var url = '/api/knowledge/getChapterMenu/?BookID=' + BookID + '&guid=' + guid;
	    G_AjaxApiVideo_OSS.get(url, false, function (json) {
	        var jsonData = JSON.parse(json);
	        if (jsonData.status === 200) {
	            var data = jsonData.data;
	            var chapterMenu = data.chapterMenu.Childs;
				for(var i=0;i<chapterMenu.length;i++){
					var liList='<li class="buy" ChapterID='+chapterMenu[i].ChapterID+' IsBuy='+chapterMenu[i].IsBuy+' IsFree='+chapterMenu[i].IsFree+' KnowNums='+chapterMenu[i].KnowNums+' OnlyCode='+chapterMenu[i].OnlyCode+'><a href="#">'+chapterMenu[i].ChapterName+'</a><span>购买</span></li>'
					$('.soft').append(liList);
					$('.soft li').each(function(){
						if($(this).attr('IsFree')==1){
							$(this).attr('class','free').find('span').text('免费体验');
						}else if($(this).attr('IsBuy')==1){
							$(this).attr('class','free').find('span').text('已购买');
						}
					})
					$('.soft li').click(function(){
						var IsFree=$(this).attr('IsFree');
						var IsBuy=$(this).attr('IsBuy');
						var ChapterID=$(this).attr('ChapterID');
						var OnlyCode=$(this).attr('OnlyCode');
						var chapterName=$(this).find('a').text();
						//console.log(chapterName)
						if(IsFree==1||IsBuy==1){
							window.location.href='/Five?ChapterID='+ChapterID+'&chapterName='+chapterName;
						}else if(IsFree==0){
							var OnlyCode=$(this).attr('OnlyCode');
							window.location.href='/buyVideo?ChapterID='+ChapterID+'&OnlyCode='+OnlyCode+'&BookID='+BookID+'&chapterName='+ escape(chapterName);
						}
					})
				}
				myscroll.refresh();
	        } else {
	            alert('知识点章节数据为空');
	        }
	    });
	}
});
function _getClientType() {
    var browser = {
        versions: function () {
            var u = navigator.userAgent,
                app = navigator.appVersion;
            return {
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
                iPad: u.indexOf('iPad') > -1,
                webApp: u.indexOf('Safari') == -1
            };
        }()
    };
    if (browser.versions.iPhone || browser.versions.iPad) {
        return 'web_iPhone';
    }
    if (browser.versions.ios || browser.versions.android || browser.versions.webApp) {
        return 'web_android';
    }
    return 'web_pc';
}
